<?php

namespace app\index\controller;

use app\index\model\Banner as BannerModel;
use think\Controller;
use think\Request;
use app\index\model\CompanyNews as CompanyNewsModel;
use app\index\model\IndustryNews as IndustryNewsModel;

class News extends BaseController
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $banner = BannerModel::getBanner('news');
        $action = $request->action();
        $this->assign('banner', $banner);
        $this->assign('action', $action);
    }

    /**
     * 新闻咨询
     */
    public function lists()
    {
        //最新5条
        $news = CompanyNewsModel::getLastNews();
        //全部
        $lists = CompanyNewsModel::getNews();
        $this->paginate($lists->lastPage(), $lists->currentPage());
        $this->assign('news', $news);
        $this->assign('lists', $lists);
        return $this->fetch();
    }

    /**
     * 加载更多
     */
    public function _ajax()
    {
        $count = $this->request->get('count');
        $lists = CompanyNewsModel::getNews($count);
        return $this->successes([
            'lists' => $lists->items(),
            'total' => $lists->total(),
            'current_page' => $lists->currentPage(),
            'last_page' => $lists->lastPage()
        ]);
    }

    /**
     * 新闻详情
     */
    public function detail($id = 0)
    {
        $news = CompanyNewsModel::getById($id);
        $preId = CompanyNewsModel::getPreId($id);
        $nextId = CompanyNewsModel::getNextId($id);
        $this->assign('preId', $preId);
        $this->assign('nextId', $nextId);
        $this->assign('news', $news);
        return $this->fetch();
    }



}
